local M = require "packages/mamashengde/record/Made"

local moli = fk.CreateSkill {
  name = "dongwan__moli",
  tags = { M.HenshinSkill },
}

Fk:loadTranslationTable {
  ["dongwan__moli"] = "魔力",
  [":dongwan__moli"] = "<a href='#made_henshin_skill'><font color='pink'>变身技</font></a>（0/5），游戏开始时或当你于摸牌阶段外获得牌时，你获得1点魔力；"..
  "结束阶段，你<a href='dongwan__Henshin'><font color='pink'>进行吟唱并变身</font></a>。",
  ["dongwan__Henshin"] = "在对应的时机点，若你的魔力已达上限，你可以吟唱咒语并变身为闪耀战姬！<br>" ..
  "<b>圣焰</b>：锁定技，你使用牌时额外结算一次，然后你消耗1点魔力或失去1点体力，对一名其他角色造成1点火焰伤害。<br>" ..
  "<b>共鸣</b>：当你消耗1点魔力后或失去1点体力后，你可以令称号与你相同的角色各摸X张牌（X为你本次变身此技能发动的次数）。",

  ["$dongwan__moli1"] = "马猴烧酒，很行！", -- 吟唱
  ["$dongwan__moli2"] = "Henshin！",
}

moli:addEffect(fk.GameStart, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return  player:hasSkill(moli.name) and M.getMaryoku(player) < M.getMaryokuMax(player)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    M.changeMaryoku(player, 1, moli.name)
  end,
})

moli:addEffect(fk.AfterCardsMove, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(moli.name) and M.getMaryoku(player) < M.getMaryokuMax(player) then
      for _, move in ipairs(data) do
        if move.to and move.to == player and move.toArea == Player.Hand and player.phase ~= Player.Draw then
          return true
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    M.changeMaryoku(player, 1, moli.name)
  end,
})

moli:addEffect(fk.EventPhaseStart, {
  anim_type = "big",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(moli.name) and
      player.phase == Player.Finish and
      M.getMaryoku(player) >= M.getMaryokuMax(player) and
      player.general == "shine__dongwan"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local target_general = "shine2__dongwan" -- 目标武将
    if M.enterHenshin(player, target_general, moli.name) then
        -- 变身成功后的处理
        room:notifySkillInvoked(player, moli.name, "positive")
    end
  end,
})

moli:addAcquireEffect(function (self, player)
  if M.getMaryokuMax(player) == 0 then
    M.setMaryokuMax(player, 5, moli.name)
  end
end)

return moli